package cn.wolfcode.web.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LoginIterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        //从session中获取当前登录对象
        HttpSession session = request.getSession();
        Object employee = session.getAttribute("EMPLOYEE_IN_SESSION");

        //判断是否为空  如果为空就代表当前没有登录,  true没登录/false登录
        if(employee == null){
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
